package com.hy.item.web;


import com.hy.item.pojo.SpecGroup;
import com.hy.item.pojo.SpecParam;
import com.hy.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("spec")
public class SpecificationController {
    @Autowired
    private SpecificationService specificationService;
    /**
     * 通过分类id查询规格组
     * @return
     */
    @GetMapping("groups/{cid}")
    public ResponseEntity<List<SpecGroup>> queryGroupByCid(@PathVariable("cid") Long cid){

    return ResponseEntity.ok(specificationService.queryGroupByCid(cid));

    }

    /**
     * 根据参数查询规格参数
     */
    @GetMapping("params")
    public ResponseEntity<List<SpecParam>>queryParamList(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required =false) Boolean searching

    ){

        return ResponseEntity.ok(specificationService.queryParamList(gid,cid,searching));

    }
    /**
     * 根据分类查询规格组及组内属性
     * @param cid
     * @return
     */
    @GetMapping("group")
    public ResponseEntity<List<SpecGroup>> queryListByCid(@RequestParam("cid") Long cid){

        return ResponseEntity.ok(specificationService.queryListByCid(cid));

    }
}
